<!--
 * @Author: Bennty
 * @Date: 2024-07-19 12:59:53
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2024-09-14 14:20:34
 * @Description: 请填写简介
-->
<template>
    <el-dialog v-model="props.visible" title="新增线索" @close="handleClose" destory-on-close>
        <el-form :model="formData" ref="formRef">
            <el-row :gutter="50">
                <el-col :span="12">
                    <el-form-item label="客户名称" prop="customerName">
                        <el-input v-model="formData.customerName" placeholder="请输入" />
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="下次跟进时间" prop="nextContactDate">
                        <el-date-picker type="date" placeholder="下次跟进时间" v-model="formData.nextContactDate" format="YYYY-MM-DD" value-format="YYYY-MM-DD" />
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row :gutter="50">
                <el-col :span="12">
                    <el-form-item label="联系人" prop="linkName">
                        <el-input v-model="formData.linkName" placeholder="请输入" />
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="联系方式" prop="lastFollowMethod">
                        <el-select v-model="formData.lastFollowMethod">
                            <el-option v-for="item in props.contract" :key="item.value" :label="item.label" :value="item.value"></el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row :gutter="50">
                <el-col :span="12">
                    <el-form-item label="联系电话" prop="linkMobile">
                        <el-input v-model.number="formData.linkMobile" placeholder="请输入"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="线索来源" prop="customerSource">
                        <el-select v-model="formData.customerSource" placeholder="请选择">
                            <el-option v-for="item in props.customerSource" :key="item.value" :label="item.label" :value="item.value"></el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row :gutter="50">
                <el-col :span="12">
                    <el-form-item label="联系微信" prop="weChat">
                        <el-input v-model="formData.weChat" placeholder="请输入"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                </el-col>
            </el-row>
            <el-form-item label="最近跟进信息" prop="remark">
                <el-input type="textarea" v-model="formData.remark" placeholder="请输入"></el-input>
            </el-form-item>
        </el-form>
        <template #footer>
            <div class="dialog-footer">
                <el-button  type="primary" @click="handleSubmit">确 定</el-button>
                <el-button @click="handleClose">取 消</el-button>
            </div>
        </template>
    </el-dialog>
</template>

<script setup lang="ts">
import type { FormInstance } from 'element-plus';
import {addClueApi} from '@/api/sj/clue-crm/index';
const formRef = ref<FormInstance>();

const props = defineProps(['visible', 'customerSource','contract']);
const emits = defineEmits(['close','submit']);
const initFormData = reactive({
    customerName: undefined,
    nextContactDate: undefined,
    linkName: undefined,
    lastFollowMethod: undefined,
    linkMobile: undefined,
    customerSource: undefined,
    weChat: undefined,
    remark: undefined,
    clueStatus: 1
});

const data = reactive({
    formData: {...initFormData}
});

const { formData } = toRefs(data);

const handleSubmit = async () => {
    await addClueApi(formData.value).then((result)=>{
        if(result.code == 200){
            emits('submit',true);
        }else{
            emits('submit',false);
        }
    });
}

const handleClose = ()=>{
    emits('close');
};
</script>

<style scoped>
.dialog-footer{
    display:flex;
    justify-content: center;
}
</style>